<?php 
    session_start();
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        
        <link rel="stylesheet" href="styles/layout.css" type="text/css"/>
        <link rel="stylesheet" href="styles/computer.css" type="text/css"/>
        <script type="text/javascript" src="scripts/computer.js"></script>
        
    </head>
    <body>

        <?php        require 'header.html';
        ?>
        
        <div id="container">
  <div class="wrapper">
    <div id="content">
    	<div id="order">
        <?php
        // put your code here
        echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];
        if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "administrator")){
            
        
            $userID = $_POST["userID"];
            if(strlen($userID) == 0){
                //add a new user
                echo "<h2>Add a new user</h2>";
            }else{
                echo "<h2>Change selected user</h2>";
                $con = mysql_connect("localhost", "zhouzhao", "19831022");
                if(!$con){
                    die("could not connect to DB: ".mysql_error());
                }
                
                mysql_select_db("cloudcom", $con);
                $result = mysql_query("select * from users where userID = $userID");
                $row = mysql_fetch_assoc($result);
                
                mysql_close($con);
            }
            
        ?>
        
        <form method="post" action="commitUser.php">
            <input type="text" name="userID" style="display: none"
                   <?php
                   if(strlen($userID) != 0){
                       echo "value='".$userID."'";
                   }
                   ?>
                   />
        <p>Username: <input type="text" name="username" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($userID) != 0){
                             echo "value='".$row["username"]."'";
                         }
                         ?>
                         /></p>
        <p>Password: <input type="password" name="password" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($userID) != 0){
                             echo "value='".$row["password"]."'";
                         }
                         ?>
                         /></p>
        <p>First name: <input type="text" name="firstName" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($userID) != 0){
                             echo "value='".$row["firstName"]."'";
                         }
                         ?>
                           /></p>
        <p>Last name: <input type="text" name="lastName" maxlength="20" class="rightAlign"
                          <?php
                          if(strlen($userID) != 0){
                              echo "value='".$row["lastName"]."'";
                          }
                          ?>
                          /></p>
        <p>DoB: <input type="text" name="dob" class="rightAlign"
                        <?php
                        if(strlen($userID) != 0){
                            echo "value='".$row["dob"]."'";
                        }
                        ?>
                    /></p>
        User type:<br/>
        <input type="radio" name="userType" value="administrator"
                          <?php
                          if(strlen($userID) != 0 && !strcmp($row["userType"], "administrator")){
                              echo "checked";
                          }?>
                          />Administrator<br/>
        <input type="radio" name="userType" value="manager"
                          <?php
                          if(strlen($userID) != 0 && !strcmp($row["userType"], "manager")){
                              echo "checked";
                          }?>
                          />Manager<br/>
        <input type="radio" name="userType" value="seller"
                          <?php
                          if(strlen($userID) != 0 && !strcmp($row["userType"], "seller")){
                              echo "checked";
                          }?>
                          />Seller<br/>
        <input type="submit" name="button" value="Commit user" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        <input type="submit" name="button" value="Cancel" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form>
        
        <?php }else{
                require 'login.html';
        }
        ?>
            
    </div>	
    </div>
    <br class="clear" />
  </div>
</div>
        
        <?php        require 'tail.html';
        ?>
        
    </body>
</html>
